﻿using UnityEngine;

public class UILabelBounce : MonoBehaviour
{
    public float bounceHeight = 20f; // 跳动的高度  
    public float bounceSpeed = 2f;    // 跳动的速度  

    private Transform rectTransform;
    private Vector3 originalPosition;

    void Start()
    {
        rectTransform = GetComponent<Transform>(); // 获取RectTransform组件  
        originalPosition = rectTransform.localPosition; // 保存初始位置  
    }

    void Update()
    {
        // 通过正弦函数计算新的Y位置  
        float newY = originalPosition.y + Mathf.Sin(Time.time * bounceSpeed) * bounceHeight;

        // 更新UI元素的位置  
        rectTransform.localPosition = new Vector3(originalPosition.x, newY, originalPosition.z);
    }
}